import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ClientsModule, Transport } from '@nestjs/microservices';

@Module({
  imports: [
    ClientsModule.register([
      // 导入一个微服务 127.0.0.1:3001，并明明为 MATH_SERVICE，模块中就能通过@Inject('MATH_SERVICE')来使用
      {
        name: 'MATH_SERVICE',
        transport: Transport.TCP,
        options: {
          // host: 'main',
          host: process.env.NODE_ENV == 'production' ? 'main' : 'localhost', // docker-compose 的 main
          port: 3001,
        },
      },
    ]),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
